Skip to content

adding missing code in a snippet #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2022

Conversation

devkiloton
Copy link
Contributor

@devkiloton devkiloton commented Apr 17, 2022

In the firebase documentation for writing and reading data there is a code snippet (the only one actually) that does not have the necessary imports. I spent a few hours on stack overflow looking for the problem because I was getting errors in my React Native app, but it was actually the documentation that did not say I had to do the imports.

The snippet is in the "Updating or deleting data" section
https://firebase.google.com/docs/database/web/read-and-write#updating_or_deleting_data

image

@thatfiredev
Copy link
Member

thatfiredev commented Apr 21, 2022

@devkiloton Thanks for your contribution. The build is failing because you're not supposed to edit that file directly.
Instead you should update the /database-next/read-and-write.js file. I can see in the writeNewPost_wrapped() function that the imports are already there, they just happen to be outside of the snippet comments (// [START rtdb_social_write_fan_out]).

So the best solution here would be to move that snippet comment to the start of the function so that the imports are shown:

function writeNewPost_wrapped() {
  // [START rtdb_social_write_fan_out]
  const { getDatabase, ref, child, push, update } = require("firebase/database");

@thatfiredev
Copy link
Member

@devkiloton Please also undo the change that you made to the generated file.

@devkiloton
Copy link
Contributor Author

@devkiloton Thanks for your contribution. The build is failing because you're not supposed to edit that file directly. Instead you should update the /database-next/read-and-write.js file. I can see in the writeNewPost_wrapped() function that the imports are already there, they just happen to be outside of the snippet comments (// [START rtdb_social_write_fan_out]).

So the best solution here would be to move that snippet comment to the start of the function so that the imports are shown:

function writeNewPost_wrapped() {
  // [START rtdb_social_write_fan_out]
  const { getDatabase, ref, child, push, update } = require("firebase/database");

Thanks @thatfiredev! I can't believe that the answer for the problem was literally in my screen.

Screen Shot 2022-04-21 at 08 34 31

Copy link
Member

@thatfiredev thatfiredev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thatfiredev thatfiredev enabled auto-merge (squash) April 21, 2022 13:23
@devkiloton
Copy link
Contributor Author

devkiloton commented Apr 21, 2022

LGTM

@thatfiredev should not I create a commit with the generated file? "npm run snippets" will do that.
Screen Shot 2022-04-21 at 11 12 10

@thatfiredev
Copy link
Member

@devkiloton Oops, my bad! Seems like you're right, please do commit the generated file.

auto-merge was automatically disabled April 21, 2022 14:27

Head branch was pushed to by a user without write access

@thatfiredev thatfiredev enabled auto-merge (squash) April 21, 2022 14:29
@thatfiredev thatfiredev merged commit 9bdf357 into firebase:master Apr 21, 2022
@devkiloton
Copy link
Contributor Author

Thanks for the support @thatfiredev!

@thatfiredev
Copy link
Member

@devkiloton the change is now live in the docs. 🎉

@devkiloton
Copy link
Contributor Author

@devkiloton the change is now live in the docs. 🎉

@thatfiredev dude, this is insane! Firebase has a piece of me now haha! Thanks for the support again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants